<?php

class Log extends Component implements ILog
{
    // Log Types
    const EMERG   = 0;  // Emergency: system is unusable
    const ALERT   = 1;  // Alert: action must be taken immediately
    const CRIT    = 2;  // Critical: critical conditions
    const ERR     = 3;  // Error: error conditions
    const WARN    = 4;  // Warning: warning conditions
    const NOTICE  = 5;  // Notice: normal but significant condition
    const INFO    = 6;  // Informational: informational messages
    const DEBUG   = 7;  // Debug: debug messages
    
    //Format types
    const FORMAT_SIMPLE = 0;
    const FORMAT_XML = 1;
    
    //Writer types
    const WRITER_STREAM   = 0;
    const WRITER_DATABASE   = 1;
    const WRITER_FIREBUG    = 2;
    const WRITER_EMAIL    = 3;
    
    private $_userDefinedPriorities = array();
    
    private $_adapter = null;
    
    public function __construct()
    {
        parent::__construct();
        $this->_adapter = new ZendLogAdapter();    
    }
    
    public function __get($key)
    {
        if(array_key_exists($key, $this->_userDefinedPriorities))
        {
            return $this->_userDefinedPriorities[$key];
        }
    }
    
    public function addPriority($priorityName, $level)
    {
        $this->_adapter->addPriority($priorityName, $level);
        $this->_userDefinedPriorities[$priorityName] = $level;
    }
    
    public function log($message, $priority)
    {
        $this->_adapter->log($message, $priority);
    }
    
    public function addWriter($writer)
    {
        $this->_adapter->addWriter($writer);
    }
    
    public function addFilter($filter)
    {
        $this->_adapter->addFilter($filter);
    }
    
    public static function createWriter($writerType)
    {
        switch ($writerType)
        {
            case self::WRITER_STREAM :
                return new LogWriterStream();
                break;
        }
    }
    
    public static function createFormatter($formatterType)
    {
        switch ($formatterType)
        {
            case self::FORMAT_SIMPLE :
                return new LogFormatterSimple(Log::FORMAT_SIMPLE);
                break;
            case self::FORMAT_XML :
                return new LogFormatterXml(Log::FORMAT_XML);
                break;
        }
    }
}

?>